<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="ctp" uri="http://www.seeyon.com/ctp"%>
<c:set var="path" value="${pageContext.request.contextPath}" />
   
 setTimeout("initKK()",1200);
 setTimeout("initKKqa()",1200);
 setTimeout("initKKshowName()",1200);
 setTimeout("initKKOldData()",1200);

function isEmptyString(strIn) {
    if (strIn === undefined) {
        return true;
    } else if (strIn == null) {
        return true;
    } else if (strIn == "") {
        return true;
    } else {
        return false;
    }
}

function initKK() {
	window.thirdPartyFormAPI.registerEvent('afterFormFieldChange',
			function(event) {				
				if (event.display == '审批流程') {
				    var params =[];
				    var _selectMemberJson={};
				     var _formData= window.thirdPartyFormAPI.getFormData();
					   var _fieldinfo=_formData.formData.tableInfo.formmain.fieldInfo;
					   var _tableName=_formData.formData.tableInfo.formmain.tableName;
					 if(!isEmptyString(event.value)){					 
					   var _member=event.value.split(",");
					   if(_tableName == "formmain_0125" || _tableName == "formmain_0067" || _tableName == "formmain_0035" || _tableName == "formmain_0033"){
					   if(_member.length > 5){
					   	alert("审批协议流程节点人数不能超过4人，请调整流程！");
					   	return;
					   }
					   }else{
					   if(_member.length >9){
					   	alert("审批协议流程节点人数不能超过9人，请调整流程！");
					   	return;
					   }}
					   for(var num=0;num < _member.length;num++){
					       var _mv=_member[num].split("|");
					       _selectMemberJson['审批'+(num+1)]={"showValue":_mv[1],"showValue2":_member[num],"value":_mv[0]};
					       _selectMemberJson['审批'+(num+1)+'-姓名']={"showValue":_mv[1],"showValue2":_member[num],"value":_mv[0]};
					   } 
					   }
					  
				       for(var num=1;num<=10;num++){
					       for (var _field in _fieldinfo)
						   {
	  						 if(_fieldinfo[_field].display==("审批"+num)){
	  						       var _fv={   "tableName" : _tableName,  
													"tableCategory" : "formmain",  
													"updateData" : {},
													"updateRecordId" : ""
												}
									_fv.updateData[_field]={"showValue":"","showValue2":"","value":""};			
	  						       if(!!_selectMemberJson["审批"+num]){
	  						         _fv.updateData[_field]=_selectMemberJson["审批"+num];
	  						       } 
	  						       params.push(_fv) 
	  						 }
	  				
	  						 if(_fieldinfo[_field].display==("审批"+num+"-姓名")){
	  						  var _fv={   "tableName" : _tableName,  
													"tableCategory" : "formmain",  
													"updateData" : {},
													"updateRecordId" : ""
												}
									_fv.updateData[_field]={"showValue":"","showValue2":"","value":""};			
	  						       if(!!_selectMemberJson["审批"+num+"-姓名"]){
	  						         _fv.updateData[_field]=_selectMemberJson["审批"+num+"-姓名"];
	  						       } 
	  						       params.push(_fv) 
	  						 }
						   }
					   }
					   window.thirdPartyFormAPI.backfillFormControlData(params);
				    }else if (event.display == '抄送-填写') {
				      var _formData= window.thirdPartyFormAPI.getFormData();
					   var _fieldinfo=_formData.formData.tableInfo.formmain.fieldInfo;
					   var _tableName=_formData.formData.tableInfo.formmain.tableName;
			    		var _member=event;
			    		 for (var _field in _fieldinfo){
			    			if(_fieldinfo[_field].display==('抄送-显示')){
			    					var _fv={   
		    								"tableName" : _tableName,  
											"tableCategory" : "formmain",  
											"updateData" : {},
											"updateRecordId" : ""
											}
			    				if(isEmptyString(_fieldinfo[_field].value)){
									_fv.updateData[_field]={"showValue":_member.showValue,"showValue2":_member.value};	
			    				}else{
			    				var showValue = _fieldinfo[_field].showValue+'、'+_member.showValue;
			    				var showValue2 = _fieldinfo[_field].showValue2+','+_member.value;
			    				_fv.updateData[_field]={"showValue":showValue,"showValue2":showValue2};
			    				}			
  						      window.thirdPartyFormAPI.backfillFormControlData(_fv);
  						   }
			    		}
				    }
			});
}
function initKKqa() {
    window.thirdPartyFormAPI.registerEvent('formFieldDbclick',
			function(event) {
			var _formData= window.thirdPartyFormAPI.getFormData();
			 if (event.display == '详细内容') {
				    if(_formData.formData.content.moduleTemplateId == '-1')
				   		 window.open("${pageContext.request.contextPath}/showUeditor.do?method=showUeditor&id="+ _formData.formData.content.contentDataId,'_blank','top=10,resizable=yes,scrollbars=yes');	
				    else	
				    	 window.open("${pageContext.request.contextPath}/showUeditor.do?method=catUeditor&id="+ _formData.formData.content.contentDataId,'_blank','top=10,resizable=yes,scrollbars=yes');	 		
				    }
				 if(event.display == '打印预览')  {
						 window.open("${pageContext.request.contextPath}/showUeditor.do?method=showPrint&id="+ _formData.formData.content.contentDataId,'_blank','top=10,resizable=yes,scrollbars=yes');	
				 } 
			});
}

function initKKshowName() {
		var params = [];
		var _selectMemberJson = {};
		if(window.thirdPartyFormAPI === undefined) return;
		var _formData= window.thirdPartyFormAPI.getFormData();
	   	var _fieldinfo=_formData.formData.tableInfo.formmain.fieldInfo;
	  	var _tableName=_formData.formData.tableInfo.formmain.tableName;
		var _selectCSJson = {};
		
		for (var _field in _fieldinfo){
			if(_fieldinfo[_field].display==('抄送-填写')){
			var _memberName = _fieldinfo[_field].showValue.split(",");
			var _memberId = _fieldinfo[_field].value.split(",");
			var _name='';
			var _id = '';
			  for(var num = 0; num < _memberName.length; num++) {
			  	_name += _memberName[num]+",";
			  	_id += _memberId[num]+"|"+_memberName[num]+",";
			  }
			  if(_memberName != ''){
		    	_selectCSJson['抄送-显示'] = {
						"showValue":_name,
						"showValue2":_id
					};
				}
				}
		}
		
		for (var _field in _fieldinfo){
			if(_fieldinfo[_field].display == '审批流程') {
				if(_fieldinfo[_field].showValue !== "") {
					var _memberName = _fieldinfo[_field].showValue.split(",");
					var _memberId = _fieldinfo[_field].value.split(",");
					for(var num = 0; num < _memberName.length; num++) {
						_selectMemberJson['审批' + (num + 1) + '-姓名'] = {
							"showValue":_memberName[num],
							"showValue2": _memberId[num] + "|"+ _memberName[num],
							"value": _memberId[num]
						};
						_selectMemberJson['审批' + (num + 1)] = {
							"showValue":_memberName[num],
							"showValue2": _memberId[num] + "|"+ _memberName[num],
							"value": _memberId[num]
						};
					}
				}
				var _count = 10;
				if(_tableName == "formmain_0125" || _tableName == "formmain_0067" || _tableName == "formmain_0035" || _tableName == "formmain_0033" || _tableName == "formmain_0192"){
				_count=4
				}
				for(var num = 1; num <= _count; num++) {
					for(var _field in _fieldinfo) {
						if(_fieldinfo[_field].display == ("审批" + num + "-姓名")) {
							var _fv = {
								"tableName": _tableName,
								"tableCategory": "formmain",
								"updateData": {},
								"updateRecordId": ""
							};
							_fv.updateData[_field] = {
								"showValue": "",
								"showValue2": "",
								"value": ""
							};
							if(!!_selectMemberJson["审批" + num + "-姓名"]) {
								_fv.updateData[_field] = _selectMemberJson["审批" + num + "-姓名"];
							}
							params.push(_fv)
						}
						if(_fieldinfo[_field].display == ("审批" + num)) {
							var _fv = {
								"tableName": _tableName,
								"tableCategory": "formmain",
								"updateData": {},
								"updateRecordId": ""
							};
							_fv.updateData[_field] = {
								"showValue": "",
								"showValue2": "",
								"value": ""
							};
							if(!!_selectMemberJson["审批" + num ]) {
								_fv.updateData[_field] = _selectMemberJson["审批" + num];
							}
							params.push(_fv)
						}
					}
				}
				window.thirdPartyFormAPI.backfillFormControlData(params);
			}
			if(_fieldinfo[_field].display==('抄送-显示')){
			    					var _fv={   
		    								"tableName" : _tableName,  
											"tableCategory" : "formmain",  
											"updateData" : {},
											"updateRecordId" : ""
											}
											
									if(!!_selectCSJson['抄送-显示']) {
			    						_fv.updateData[_field] = _selectCSJson['抄送-显示'];	
  						     			 window.thirdPartyFormAPI.backfillFormControlData(_fv);
  						      }
  						   }
	}
	
}
window.parent.initContentDataId=function() {
		var _formData= window.thirdPartyFormAPI.getFormData();
		return  _formData.formData.content.contentDataId;				
}
 function getTest(){
			var html = '';
			html = $(".cap4-formmain").html().toString();
			return html;
		}
		
		
function initKKOldData() {
    window.thirdPartyFormAPI.registerEvent('formFieldDbclick',
			function(event) {
			var _formData= window.thirdPartyFormAPI.getFormData();
			 if (event.display == '历史数据正文') {
			 		var _fielNo = _formData.formmains.formmain_0197.field0001.value;
					window.open("${pageContext.request.contextPath}/editOpinion.do?method=getOldDataByFielNo&fielNo="+ _fielNo,'_blank','top=10,resizable=yes,scrollbars=yes');
				  } 
			});
      }		
		
